<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="产品代码" prop="productCode">
        <el-input v-model="queryParams.productCode" placeholder="请输入产品代码" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="产品名称" prop="productName">
        <el-input v-model="queryParams.productName" placeholder="请输入产品名称" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
     <!-- <el-form-item label="产品范畴" prop="productType">
        <el-select v-model="queryParams.productType" placeholder="请选择产品范畴" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item> -->
      <el-form-item label="延期产品等级" prop="creditRating">
        <el-input v-model="queryParams.creditRating" placeholder="请输入延期产品等级" clearable
          size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>
     <!-- <el-form-item label="期数" prop="periodNum">
        <el-input v-model="queryParams.periodNum" placeholder="请输入期数" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="单位" prop="unit">
        <el-input v-model="queryParams.unit" placeholder="请输入单位" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="产品展示利率" prop="showInterestRate">
        <el-input v-model="queryParams.showInterestRate" placeholder="请输入产品展示利率" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="展示服务费率" prop="showServiceRate">
        <el-input v-model="queryParams.showServiceRate" placeholder="请输入展示服务费率" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="是否支持延期产品0不支持1支持" prop="isDeferred">
        <el-input v-model="queryParams.isDeferred" placeholder="请输入是否支持延期产品0不支持1支持" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="产品金融标签,逗号隔开，-1:0利息产品，-2:延期产品  ,%折扣商品" prop="tags">
        <el-input v-model="queryParams.tags" placeholder="请输入产品金融标签,逗号隔开，-1:0利息产品，-2:延期产品  ,%折扣商品" clearable
          size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="延期最大天数" prop="deferredMaxDays">
        <el-input v-model="queryParams.deferredMaxDays" placeholder="请输入延期最大天数" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="利(息)率" prop="interestRate">
        <el-input v-model="queryParams.interestRate" placeholder="请输入利(息)率" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="服务费率" prop="serviceFee">
        <el-input v-model="queryParams.serviceFee" placeholder="请输入服务费率" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="趸交" prop="isSinglePayment">
        <el-input v-model="queryParams.isSinglePayment" placeholder="请输入趸交" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="授信比例" prop="creditScale">
        <el-input v-model="queryParams.creditScale" placeholder="请输入授信比例" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="最低贷款额度" prop="minQuota">
        <el-input v-model="queryParams.minQuota" placeholder="请输入最低贷款额度" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="最高贷款额度" prop="maxQuota">
        <el-input v-model="queryParams.maxQuota" placeholder="请输入最高贷款额度" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="生效起始日期" prop="startDate">
        <el-date-picker clearable size="small" v-model="queryParams.startDate" type="date" value-format="yyyy-MM-dd"
          placeholder="选择生效起始日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="生效结束日期" prop="endDate">
        <el-date-picker clearable size="small" v-model="queryParams.endDate" type="date" value-format="yyyy-MM-dd"
          placeholder="选择生效结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="滞纳金日费率" prop="dateLateFee">
        <el-input v-model="queryParams.dateLateFee" placeholder="请输入滞纳金日费率" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="滞纳金按日收费宽限期" prop="lateFeeGracePeriod">
        <el-input v-model="queryParams.lateFeeGracePeriod" placeholder="请输入滞纳金按日收费宽限期" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="滞纳金计算最大天数" prop="lateFeeMaxDays">
        <el-input v-model="queryParams.lateFeeMaxDays" placeholder="请输入滞纳金计算最大天数" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="是否默认产品 Y是；N否" prop="defult">
        <el-input v-model="queryParams.defult" placeholder="请输入是否默认产品 Y是；N否" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="状态" prop="state">
        <el-input v-model="queryParams.state" placeholder="请输入状态" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['bizsys:info:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['bizsys:info:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['bizsys:info:remove']">删除</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['bizsys:info:export']">导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="延期产品代码" align="center" prop="productCode" />
      <el-table-column label="延期产品名称" align="center" prop="productName" />
      <el-table-column label="延期产品等级" align="center" prop="creditRating" />
      <el-table-column label="延期产品利(息)率" align="center" prop="interestRate" />
      <el-table-column label="延期产品服务费率" align="center" prop="serviceRate" />
      <el-table-column label="单次延期天数" align="center" prop="numDeferredDay" />
      <el-table-column label="延期期数" align="center" prop="numDeferredTimes" />
      <el-table-column label="延期产品保留天数" align="center" prop="numDeferredRetainDay" />
      <el-table-column label="延期还款最低本金" align="center" prop="minRepayPrincipal" />
      <el-table-column label="延期还款最高本金" align="center" prop="maxRepayPrincipal" />
      <el-table-column label="延期产品过期时间" align="center" prop="expireTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.expireTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="延期产品是否激活" align="center" prop="status" :formatter="statusFormatter"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['bizsys:info:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['bizsys:info:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改借款产品信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">
        <el-form-item label="延期产品代码" prop="productCode">
          <el-input v-model="form.productCode" placeholder="请输入产品代码" />
        </el-form-item>
        <el-form-item label="延期产品名称" prop="productName">
          <el-input v-model="form.productName" placeholder="请输入产品名称" />
        </el-form-item>
       <!-- <el-form-item label="产品范畴" prop="productType">
          <el-select v-model="form.productType" placeholder="请选择产品范畴">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item> -->
        <el-form-item label="延期产品等级" prop="creditRating">
          <el-input v-model="form.creditRating" placeholder="请输入延期产品等级" />
        </el-form-item>
        <el-form-item label="延期产品利(息)率" prop="interestRate">
          <el-input v-model="form.interestRate" placeholder="请输入利(息)率" />
        </el-form-item>
        <el-form-item label="延期产品服务费率" prop="serviceRate">
          <el-input v-model="form.serviceRate" placeholder="请输入服务费率" />
        </el-form-item>
        <el-form-item label="延期期数" prop="numDeferredTimes">
          <el-input v-model="form.numDeferredTimes" placeholder="请输入期数" />
        </el-form-item>
        <el-form-item label="单次延期天数" prop="numDeferredDay">
          <el-input v-model="form.numDeferredDay" placeholder="请输入单次延期天数" />
        </el-form-item>
        <el-form-item label=" 延期产品保留天数" prop="numDeferredRetainDay">
          <el-input v-model="form.numDeferredRetainDay" placeholder="延期产品保留天数" />
        </el-form-item>
        <el-form-item label="延期还款最低本金" prop="minRepayPrincipal">
          <el-input v-model="form.minRepayPrincipal" placeholder="请输入延期还款最低本金" />
        </el-form-item>
        <el-form-item label="延期还款最高本金" prop="maxRepayPrincipal">
          <el-input v-model="form.maxRepayPrincipal" placeholder="请输入延期还款最高本金" />
        </el-form-item>
        <el-form-item label="延期产品过期时间" prop="expireTime">
          <el-date-picker class="width100" clearable size="small" v-model="form.expireTime" type="date" value-format="yyyy-MM-dd"
            placeholder="选择延期产品过期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="延期产品是否激活" prop="showIsActive">
          <el-select class="width100"  v-model="form.showIsActive" placeholder="请选择状态">
            <el-option v-for="dict in stateOptions" :key="dict.key" :label="dict.value"
              :value="dict.key"></el-option>
          </el-select>
          <!-- <el-input v-model="form.showInterestRate" placeholder="请选择延期产品是否激活" /> -->
        </el-form-item>


        <!-- <el-form-item label="产品展示利率" prop="showInterestRate">
          <el-input v-model="form.showInterestRate" placeholder="请输入产品展示利率" />
        </el-form-item>
        <el-form-item label="展示服务费率" prop="showServiceRate">
          <el-input v-model="form.showServiceRate" placeholder="请输入展示服务费率" />
        </el-form-item>
        <el-form-item label=" 延期最大天数" prop="deferredMaxDays">
          <el-input v-model="form.deferredMaxDays" placeholder="请输入延期最大天数" />
        </el-form-item> -->


        <!-- <el-form-item label="单位" prop="unit">
          <el-input v-model="form.unit" placeholder="请输入单位" />
        </el-form-item>

        <el-form-item label="是否支持延期产品0不支持1支持" prop="isDeferred">
          <el-input v-model="form.isDeferred" placeholder="请输入是否支持延期产品0不支持1支持" />
        </el-form-item>
        <el-form-item label="产品金融标签,逗号隔开，-1:0利息产品，-2:延期产品  ,%折扣商品" prop="tags">
          <el-input v-model="form.tags" placeholder="请输入产品金融标签,逗号隔开，-1:0利息产品，-2:延期产品  ,%折扣商品" />
        </el-form-item>

        <el-form-item label="趸交" prop="isSinglePayment">
          <el-input v-model="form.isSinglePayment" placeholder="请输入趸交" />
        </el-form-item>
        <el-form-item label="授信比例" prop="creditScale">
          <el-input v-model="form.creditScale" placeholder="请输入授信比例" />
        </el-form-item>
        <el-form-item label="最低贷款额度" prop="minQuota">
          <el-input v-model="form.minQuota" placeholder="请输入最低贷款额度" />
        </el-form-item>
        <el-form-item label="最高贷款额度" prop="maxQuota">
          <el-input v-model="form.maxQuota" placeholder="请输入最高贷款额度" />
        </el-form-item>

        <el-form-item label="滞纳金日费率" prop="dateLateFee">
          <el-input v-model="form.dateLateFee" placeholder="请输入滞纳金日费率" />
        </el-form-item>
        <el-form-item label="滞纳金按日收费宽限期" prop="lateFeeGracePeriod">
          <el-input v-model="form.lateFeeGracePeriod" placeholder="请输入滞纳金按日收费宽限期" />
        </el-form-item>
        <el-form-item label="滞纳金计算最大天数" prop="lateFeeMaxDays">
          <el-input v-model="form.lateFeeMaxDays" placeholder="请输入滞纳金计算最大天数" />
        </el-form-item>
        <el-form-item label="是否默认产品 Y是；N否" prop="defult">
          <el-input v-model="form.defult" placeholder="请输入是否默认产品 Y是；N否" />
        </el-form-item>
        <el-form-item label="状态" prop="state">
          <el-input v-model="form.state" placeholder="请输入状态" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {
    listInfo,
    getInfo,
    delInfo,
    addInfo,
    updateInfo,
    exportInfo
  } from "@/api/business/info";

  export default {
    name: "Info",
    components: {},
    data() {
      return {
        stateOptions: [
        {value:'是',key:'1'},
        {value:'否',key:'0'}
        ],
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 借款产品信息表格数据
        infoList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          productCode: null,
          productName: null,
          productType: null,
          creditRating: null,
          periodNum: null,
          unit: null,
          showInterestRate: null,
          showServiceRate: null,
          isDeferred: null,
          tags: null,
          deferredMaxDays: null,
          interestRate: null,
          serviceFee: null,
          isSinglePayment: null,
          creditScale: null,
          minQuota: null,
          maxQuota: null,
          startDate: null,
          endDate: null,
          dateLateFee: null,
          lateFeeGracePeriod: null,
          lateFeeMaxDays: null,
          defult: null,
          state: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {}
      };
    },
    created() {
      this.getList();
    },
    methods: {
      statusFormatter(row){
        if(row. status == '1'){
            return '是'
        }else{
            return '否'
        }
      },
      /** 查询借款产品信息列表 */
      getList() {
        this.loading = true;
        listInfo(this.queryParams).then(response => {
          this.infoList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form ={
          state:null,
          expireTime:null,
          productCode:null,
          productName:null,
          creditRating:null,
          interestRate:null,
          serviceRate:null,
          numDeferredTimes:null,
          numDeferredDay:null,
          numDeferredRetainDay:null,
          minRepayPrincipal:null,
          maxRepayPrincipal:null,
        }
        // this.form = {
        //   id: null,
        //   productCode: null,
        //   productName: null,
        //   productType: null,
        //   creditRating: null,
        //   periodNum: null,
        //   unit: null,
        //   showInterestRate: null,
        //   showServiceRate: null,
        //   isDeferred: null,
        //   tags: null,
        //   deferredMaxDays: null,
        //   interestRate: null,
        //   serviceFee: null,
        //   isSinglePayment: null,
        //   creditScale: null,
        //   minQuota: null,
        //   maxQuota: null,
        //   startDate: null,
        //   endDate: null,
        //   dateLateFee: null,
        //   lateFeeGracePeriod: null,
        //   lateFeeMaxDays: null,
        //   defult: null,
        //   state: null,
        //   createTime: null
        // };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length != 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加借款产品信息";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || (this.ids.length == 1 ? this.ids[0] : this.ids)
        getInfo({'id':id}).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改借款产品信息";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateInfo(this.form).then(response => {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addInfo(this.form).then(response => {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$confirm('是否确认删除借款产品信息编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delInfo(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有借款产品信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportInfo(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
      }
    }
  };
</script>
<style type="text/css" scoped>
  .width100{
    width:100%
  }
  .width100 .el-date-editor.el-input{
    width:100%
  }
</style>
